package com.yfs.cloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
* @Company: 影法師工作室
* @Description: 正确解决spring cloud gateway跨域cors问题
* @author 影法師  
* @date 2020年9月7日 下午4:41:25 
* @version V1.0
 */
@Configuration
public class CorsConfig {
	@Bean
	public CorsWebFilter corsWebFilter() {
		CorsConfiguration cfg = new CorsConfiguration();
		cfg.setAllowCredentials(true);
		cfg.addAllowedOrigin("*");
		cfg.addAllowedMethod("*");
		cfg.addAllowedHeader("*");
		UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
		source.registerCorsConfiguration("/**", cfg);
		return new CorsWebFilter(source);
	}
}
